package com.ideaaedi.zoo.example.springboot.seata_dynamicds.alpha.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds.alpha.mapper.MysqlStudentMapper;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds.alpha.mapper.OracleTeacherMapper;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds.alpha.po.StudentPO;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds.alpha.po.TeacherPO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 模拟service
 */
@Component
public class BizService4Basic {
    
    @Resource
    private MysqlStudentMapper mysqlStudentMapper;
    
    @Resource
    private OracleTeacherMapper oracleTeacherMapper;
    
    //    -------------------------- mysql部分 --------------------------
    // @DS("mysqlAlpha") 不指定也可， 因为我们配置的默认数据源就是mysqlAlpha
    @Transactional(rollbackFor = Exception.class)
    public void insertStudent(StudentPO student) {
        mysqlStudentMapper.insert(student);
    }
    
    
    //    -------------------------- oracle部分 --------------------------
    
    @DS("oracleAlpha")
    @Transactional(rollbackFor = Exception.class)
// @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public void insertTeacher(TeacherPO teacher) {
        oracleTeacherMapper.insert(teacher);
    }
    
}